const query = require('./query')

const queryCategoryOne = async () => {
  const sql = `select categoryOne_id,categoryOne_name from category_one`
  try {
    const result = await query(sql)
    return result
  } catch (error) {
    return Promise.reject(error)
  }
}
const queryCategoryTwo = async (keyword) => {
  const sql = `select a.categoryTwo_id,a.categoryTwo_name
  from category_two a
  ${keyword ? keyword === '全部商品' ? ''
      : `join category_one b 
      where a.categoryOne_id = b.categoryOne_id
      and b.categoryOne_name like '%${keyword}%'` : ''}
  `
  try {
    const result = await query(sql)
    return result
  } catch (error) {
    return Promise.reject(error)
  }
}

module.exports = {
  queryCategoryOne,
  queryCategoryTwo
}